<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>莫名科技</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <script src="//g.alicdn.com/dingding/dingtalk-jsapi/2.6.41/dingtalk.open.js"></script>
</head>
<body>
    <div>
        <span style="font-size: 30px">auth_code:</span>
        <span style="font-size: 30px" id="auth-code"></span>
    </div>
    <div style="text-align: center; margin-top: 60px">
        <button style="size: 40px" onclick="refresh()">刷新</button>
    </div>
<script src="//unpkg.com/axios/dist/axios.min.js"></script>
<script>
    var code = "";

    function refresh() {
        createCode();
    }

    function createCode() {
        if (code == "") {
            alert('获取code失败，联系管理员');
            return
        }

        // 请求网络
        axios.get('/dd/code/'+code)
            .then(function (response) {
                console.log(response);
                if (response.data.code == 0) {
                    document.getElementById("auth-code").innerText = response.data.auth_code;
                    return;
                } else {
                    alert("接口返回错误");
                }
            })
            .catch(function (error) {
                console.log(error);
            });
    }

    dd.ready(function() {
        dd.runtime.permission.requestAuthCode({
            corpId: 'ding915afba9b2c6d02b', // 企业id
            onSuccess: function (info) {
                code = info.code;
                console.info("code:"+code);

                createCode();
            }});
    });

</script>
</body>
</html>